from common.base_page import BasePage
from time import sleep
from test_datas.string_data import *
from page_locators.login_page_locators import LoginPageLocators as LPL
from test_datas.file_path import *
from test_datas.pic_data import *
from page_locators.manage_organizate_page_locators import MageOrganizateLocators as MOL

class ManageOrganizate(BasePage):

    def __init__(self,driver):
        super().__init__(driver)

    def login(self, username, password):
        self.input(LPL.username_loc, username, '用户名输入失败截图')
        self.input(LPL.password_loc, password, '密码输入失败截图')
        code = self.get_code(LPL.captcha_img, '验证码图片定位', 'src')
        self.input(LPL.captcha, code, '验证码输入')
        self.click(LPL.loginsbt, '登录按钮点击失败截图')
        sleep(1)
        self.switch_window()
        sleep(1)

    def click_user_center_app(self):
        self.click(LPL.application, '用户中心应用定位点击')
        sleep(1)

    def click_add_organizate(self):
        self.click(MOL.add_organizate, "添加机构定位点击")

    def empty_organization_name(self):
        self.click_add_organizate()
        self.input(MOL.organizate_name, "", "机构全称为空")
        self.type_and_permission()
        self.click_sure()

    def space_organization_name(self):
        self.click_add_organizate()
        self.input(MOL.organizate_name, " ", "机构全称输入空格")
        self.type_and_permission()
        self.click_sure()

    def organization_name_error1(self):
        self.click_add_organizate()
        self.input(MOL.organizate_name, big_string, "机构全称输入超长字符串")

    def organization_name_error2(self):
        self.click_add_organizate()
        self.input(MOL.organizate_name, cheles51, "机构全称输入51个字符")

    def organization_name_success1(self):
        self.click_add_organizate()
        self.input(MOL.organizate_name, cheles50, "机构名称输入50个字符")
        self.type_and_permission()
        self.click_sure()
        self.input(MOL.search_box, cheles50, '名称搜索框定位输入')
        sleep(1)
        self.click_query_sub()

    def click_query_sub(self):
        self.click(MOL.query_sub, '查询按钮点击')

    def organization_name_success2(self):
        self.click_add_organizate()
        self.input(MOL.organizate_name, cheles49, "机构名称输入49个字符")
        self.type_and_permission()
        self.click_sure()
        self.input(MOL.search_box, cheles49, '名称搜索框定位输入')
        sleep(1)
        self.click_query_sub()

    def organization_name_success3(self):
        self.click_add_organizate()
        self.input(MOL.organizate_name, "测试机构-002", "机构名称输入定位输入")

    def add_organizate_mustbe_input(self):
        self.input(MOL.organizate_name, "成长小学-001", "机构名称输入定位输入")
        self.type_and_permission()
        self.address_choose()
        self.click_sure()

    def type_choose_school(self):
        self.click(MOL.type, '机构类型选择学校')

    def empty_type(self):
        self.click_add_organizate()
        self.input(MOL.organizate_name, "测试机构-001", "机构名称输入定位输入")
        self.click_sure()

    def type_and_permission(self):
        self.type_choose_school()

    def address_choose(self):
        sleep(1)
        self.click(MOL.address_box, "地址下拉框定位点击")
        sleep(1)
        self.move_embed_scroll_bar(MOL.province)
        self.click(MOL.province, '陕西省定位点击')
        sleep(1)
        self.click(MOL.city, '西安市定位点击')
        sleep(1)
        self.click(MOL.area, '雁塔区定位点击')
        sleep(1)
        self.input(MOL.full_address, '汇鑫中心-C座', '详细地址定位输入')
        sleep(2)
        self.click(MOL.first_area, '详细地址列表第一个定位点击')

    def input_full_address(self):
        self.organization_name_success3()
        self.address_choose()
        self.type_and_permission()
        self.click_sure()
        sleep(1)

    def click_sure(self):
        self.click(MOL.sure, "确定按钮定位点击")

    def click_app_permission(self):
        self.click(MOL.app_permission, "选择应用权限定位点击")
        self.click(MOL.app_center_option, "勾选应用中心选项")
        self.click(MOL.app_list_sure, "应用列表确定按钮")

    def delete_fist_list(self):
        self.click(MOL.first_list_delete, '列表第一个删除按钮定位点击')
        self.click(MOL.sure_delete, '确认删除按钮定位点击')

    def input_responsible_person(self):
        self.organization_name_success3()
        self.address_choose()
        self.type_and_permission()
        sleep(1)
        self.input(MOL.responsible_person, '张', '负责人输入超长字符串')
        sleep(2)
        self.click(MOL.first_resperson, "点击选择下拉框第一个负责人")
        self.click_sure()

    def input_responsible_person_error(self):
        self.click_add_organizate()
        self.input(MOL.responsible_person, 'gfdhfdh', '负责人输入不存在的字符')

    def delete_test_organizate_002(self):
        self.click(MOL.delete_002, '删除测试机构-002')
        self.click(MOL.sure_delete, '点击确认删除')

    def click_batch_import(self):
        self.click(MOL.batch_import_organization, '批量导入定位点击')

    def input_organizate_file1(self):
        self.upload_file(MOL.input_label, input_file1, '上传批量导入文件')

    def click_import(self):
        self.get_ele(MOL.success_tips, '文件上传成功提示信息标签')
        self.click(MOL.import_button, "导入按钮定位点击")

    def click_import_sure(self):
        self.get_ele(MOL.result_tips, '导入结果标签')
        self.click(MOL.import_sure, "批量导入确定按钮定位点击")

    def batch_import_organization(self):
        self.click_batch_import()
        self.input_organizate_file1()
        self.click_import()
        self.click_import_sure()

    def input_import_names1(self):
        sleep(1)
        self.input(MOL.search_box, "成长小学", "搜索框定位输入")
        sleep(1)

    def input_import_names2(self):
        sleep(1)
        self.input(MOL.search_box, "橙子中学", "搜索框定位输入")
        sleep(1)

    def input_import_names3(self):
        sleep(1)
        self.input(MOL.search_box, "黄山小学", "搜索框定位输入")
        sleep(1)

    def get_names(self):
        n1 = self.get_text(MOL.czxx, '成长小学名称获取')
        n2 = self.get_text(MOL.czzx, '橙子中学名称获取')
        n3 = self.get_text(MOL.hsxx, '黄山小学名称获取')
        names = f"{n1}, {n2}, {n3}"
        return names

    def batch_check(self):
        self.click(MOL.czxx_box, "成长小学定位勾选")
        self.click(MOL.czzx_box, "橙子中学定位勾选")
        self.click(MOL.hsxx_box, "黄山小学定位勾选")

    def check_one_organizate(self):
        self.click(MOL.czxx_box, "成长小学定位勾选")
        self.click_batch_assign()

    def click_batch_assign(self):
        self.click(MOL.batch_assign_button, "批量分配应用权限按钮定位点击")

    def batch_assign_app_permission(self):
        self.batch_check()
        self.click_batch_assign()

    def get_batch_assign_organization_names(self):
        name1 = self.get_text(MOL.label1, "批量分配应用权限页面-机构名称标签1定位取值")
        name2 = self.get_text(MOL.label2, "批量分配应用权限页面-机构名称标签2定位取值")
        name3 = self.get_text(MOL.label3, "批量分配应用权限页面-机构名称标签3定位取值")
        names = f"{name1}, {name2}, {name3}"
        return names

    def batch_check_app(self):
        self.input(MOL.app_name, "用户中心", "批量分配应用页面-应用名称搜索框定位输入")
        self.click(MOL.list_app1, "应用列表第一个定位点击")
        self.input(MOL.app_name, "消息中心", "批量分配应用页面-应用名称搜索框定位输入")
        self.click(MOL.list_app1, "应用列表第一个定位点击")
        self.click(MOL.assign_app_sure_button, "分配应用列表确定按钮定位点击")

    def name_search_name1(self):
        self.input(MOL.name_search, "成长小学", "机构列表名称搜索框定位输入")
        sleep(1)
        self.click_query_sub()

    def name_search_name2(self):
        self.input(MOL.name_search, "橙子中学", "机构列表名称搜索框定位输入")
        sleep(1)
        self.click_query_sub()
        sleep(1)

    def name_search_name3(self):
        self.input(MOL.name_search, "黄山小学", "机构列表名称搜索框定位输入")
        sleep(1)
        self.click_query_sub()
        sleep(1)

    def click_add_logo_button(self):
        self.name_search_name1()
        sleep(1)
        self.click(MOL.add_logo, "添加logo按钮定位点击")

    def add_logo_error1(self):
        self.click_add_logo_button()
        self.upload_file(MOL.input_logo, webp_path, "上传logo")
        self.click(MOL.add_logo_sure, "上传logo确定按钮定位点击")

    def add_logo_error2(self):
        self.click_add_logo_button()
        self.upload_file(MOL.input_logo, big_path, "上传logo")
        self.click(MOL.add_logo_sure, "上传logo确定按钮定位点击")

    def add_logo_error3(self):
        self.click_add_logo_button()
        self.upload_file(MOL.input_logo, video_path, "上传logo")
        self.click(MOL.add_logo_sure, "上传logo确定按钮定位点击")

    def add_logo_error4(self):
        self.click_add_logo_button()
        self.upload_file(MOL.input_logo, input_file1, "上传logo")
        self.click(MOL.add_logo_sure, "上传logo确定按钮定位点击")

    def add_logo_success(self):
        self.click_add_logo_button()
        self.upload_file(MOL.input_logo, cover_pic, "上传logo")
        self.click(MOL.add_logo_sure, "上传logo确定按钮定位点击")

    def click_add_department_popup(self):
        self.click(MOL.department_menu, "部门管理菜单点击")
        self.click(MOL.add_department_button, "添加部门按钮定位点击")

    def add_department(self):
        self.click(MOL.add_department_button, "添加部门按钮定位点击")
        self.input(MOL.department_name, "市场部", "部门名称定位输入")
        self.click(MOL.add_department_sure, "添加部门确定按钮定位点击")

    def click_add_department(self):
        self.click(MOL.department_menu, "部门管理菜单点击")
        self.click(MOL.department_box, "机构下拉框点击")
        sleep(1)
        self.click(MOL.drop_box1, "取消勾选机构下拉框的纳吉特第1号学校11")
        sleep(1)
        self.click(MOL.unfold_icon, "点击展开机构")
        sleep(1)
        self.click(MOL.drop_box2, "勾选机构下拉框中的成长小学")
        self.click(MOL.add_department_button, "添加部门按钮定位点击")

    def add_department_success(self):
        self.click_add_department()
        self.input(MOL.department_name, "综合服务部", "部门名称定位输入")
        self.click(MOL.add_department_sure, "添加部门确定按钮定位点击")
        sleep(1)

    def department_name_space(self):
        self.click_add_department()
        self.input(MOL.department_name, " ", "部门名称定位输入")
        self.click(MOL.add_department_sure, "添加部门确定按钮定位点击")

    def department_name_bigstr(self):
        self.click_add_department()
        self.input(MOL.department_name, big_string, "部门名称定位输入")
        self.click(MOL.add_department_sure, "添加部门确定按钮定位点击")

    def department_name_51str(self):
        self.click_add_department()
        self.input(MOL.department_name, cheles51, "部门名称定位输入")
        self.click(MOL.add_department_sure, "添加部门确定按钮定位点击")

    def department_name_50str(self):
        self.click_add_department()
        self.input(MOL.department_name, cheles50, "部门名称定位输入")
        self.click(MOL.add_department_sure, "添加部门确定按钮定位点击")
        sleep(1)

    def department_name_49str(self):
        self.click_add_department()
        self.input(MOL.department_name, cheles49, "部门名称定位输入")
        self.click(MOL.add_department_sure, "添加部门确定按钮定位点击")
        sleep(1)

    def principal_person_21str(self):
        self.click_add_department()
        self.input(MOL.department_name, "销售部", "部门名称定位输入")
        self.input(MOL.principal_person, cheles21, "负责人定位输入")
        self.click(MOL.add_department_sure, "添加部门确定按钮定位点击")

    def principal_person_20str(self):
        self.click_add_department()
        self.input(MOL.department_name, "销售部", "部门名称定位输入")
        self.input(MOL.principal_person, cheles20, "负责人定位输入")
        self.click(MOL.add_department_sure, "添加部门确定按钮定位点击")
        sleep(1)

    def principal_person_19str(self):
        self.click_add_department()
        self.input(MOL.department_name, "销售部", "部门名称定位输入")
        self.input(MOL.principal_person, cheles19, "负责人定位输入")
        self.click(MOL.add_department_sure, "添加部门确定按钮定位点击")
        sleep(1)

    def add_department_input_all(self):
        self.click_add_department()
        self.input(MOL.department_name, "研发部", "部门名称定位输入")
        self.input(MOL.principal_person, "陈宇宙", "负责人定位输入")
        self.input(MOL.tel_phone, "13120212261", "联系电话定位输入")
        self.input(MOL.add_department_sort, "1", "排序输入框定位输入")
        self.click(MOL.add_department_sure, "添加部门确定按钮定位点击")
        sleep(1)

    def delete_department_list1(self):
        self.click(MOL.department_list1_delete_sub, "部门列表第一条删除按钮定位点击")
        self.click(MOL.system_sure, "系统提示, 确定按钮定位点击")

    def add_subordinate(self):
        self.click(MOL.add_subordinate, "添加下级定位点击")
        sleep(1)
        self.add_organizate_mustbe_input()
        sleep(1)

    def search_subordinate_and_delete(self):
        self.input(MOL.name_search, "成长小学-001", "机构列表名称搜索框定位输入")
        sleep(1)
        self.click_query_sub()
        self.delete_fist_list()

    def edit_function_verify(self):
        self.click(MOL.edit_button, "编辑按钮定位点击")
        self.input(MOL.organizate_name, "成长小学1", "机构全称编辑修改")
        self.click_sure()
        sleep(1)

    def delete_added_organizates(self):
        self.input(MOL.name_search, "成长小学1", "机构列表名称搜索框定位输入")
        sleep(1)
        self.click_query_sub()
        sleep(1)
        self.delete_fist_list()
        sleep(1)
        self.name_search_name2()
        self.delete_fist_list()
        self.name_search_name3()
        self.delete_fist_list()








